package com.efuture.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @ClassNAME JdbcQueryData
 * @Description 使用jdbc查询数据
 * @Author zhaoshanshan
 * @Date 2021/9/19 7:25 下午
 * @Version 1.0
 */
public class JdbcQueryData {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rst = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root","zhaoss");
            String sql = "select * from account";
            stmt = conn.createStatement();
            rst = stmt.executeQuery(sql);
            while (rst.next()){
                int id = rst.getInt("id");
                String name = rst.getString("NAME");
                double balance = rst.getDouble("balance");
                System.out.println("id:"+id);
                System.out.println("name:"+name);
                System.out.println("balance:"+balance);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
              if(null!=conn){
                  conn.close();
              }
              if(null!=stmt){
                  stmt.close();
              }
              if(null!=rst){
                  rst.close();
              }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}